package orders

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"order_srv/orderclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateAfterSaleLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateAfterSaleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAfterSaleLogic {
	return &CreateAfterSaleLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateAfterSaleLogic) CreateAfterSale(req *types.CreateAfterSaleRequest) (resp *types.Response, err error) {
	
	sale, err := l.svcCtx.OrderRpc.CreateAfterSale(l.ctx, &orderclient.CreateAfterSaleRequest{
		OrderId: req.OrderId,
		UserId:  req.UserId,
		Type:    int32(req.Type),
		Reason:  req.Reason,
		Images:  req.Images,
	})
	if err != nil {
		return &types.Response{
			Code:    400,
			Message: err.Error(),
		}, nil
	}

	return &types.Response{
		Code:    200,
		Message: "创建售后成功",
		Data:    sale.AfterSaleId,
	}, nil
	return
}
